<template>
  <div class="sci-fi-progress-container">
    <div class="progress-header">
      <span class="progress-label">{{ label }}</span>
      <span class="progress-value">{{ currentValue.toFixed(2) }}%</span>
    </div>
    <div class="progress-wrapper">
      <div class="progress-bg">
        <div class="progress-track">
          <div 
            class="progress-fill" 
            :style="{ width: currentValue + '%' }"
          >
            <div class="progress-glow"></div>
            <div class="progress-particles">
              <span v-for="i in 6" :key="i" class="particle"></span>
            </div>
          </div>
        </div>
        <div class="progress-indicators">
          <div 
            v-for="i in 10" 
            :key="i" 
            class="indicator" 
            :class="{ active: (i * 10) <= currentValue }"
            :style="{ left: (i * 10) + '%' }"
          ></div>
        </div>
      </div>
    </div>
    <div class="progress-stats">
      <div class="stat-item">
        <span class="stat-label">目标值</span>
        <span class="stat-value">{{ targetValue }}%</span>
      </div>
      <div class="stat-item">
        <span class="stat-label">当前状态</span>
        <span class="stat-value" :class="statusClass">{{ status }}</span>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue'

interface Props {
  value?: number
  targetValue?: number
  label?: string
  status?: string
  animated?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  value: 0,
  targetValue: 100,
  label: '数据加载进度',
  status: '正常',
  animated: true
})

const currentValue = ref(0)

const statusClass = computed(() => {
  if (props.status === '异常') return 'status-error'
  if (props.status === '警告') return 'status-warning'
  return 'status-normal'
})

// 动画效果
const animateProgress = () => {
  if (!props.animated) {
    currentValue.value = props.value
    return
  }

  const duration = 2000 // 2秒动画
  const startTime = Date.now()
  const startValue = currentValue.value
  const targetValue = props.value

  const animate = () => {
    const elapsed = Date.now() - startTime
    const progress = Math.min(elapsed / duration, 1)
    
    // 使用缓动函数
    const easeOutCubic = 1 - Math.pow(1 - progress, 3)
    currentValue.value = startValue + (targetValue - startValue) * easeOutCubic
    
    if (progress < 1) {
      requestAnimationFrame(animate)
    }
  }
  
  animate()
}

watch(() => props.value, animateProgress)

onMounted(() => {
  setTimeout(() => {
    animateProgress()
  }, 300)
})
</script>

<style lang="scss" scoped>
.sci-fi-progress-container {
  background: linear-gradient(135deg, rgba(0, 255, 255, 0.05) 0%, rgba(0, 150, 255, 0.05) 100%);
  border: 1px solid rgba(0, 255, 255, 0.3);
  border-radius: 12px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(0, 255, 255, 0.8), transparent);
    animation: scan 3s linear infinite;
  }
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  
  .progress-label {
    font-size: 16px;
    font-weight: 600;
    color: #00FFFF;
    text-shadow: 0 0 10px rgba(0, 255, 255, 0.5);
  }
  
  .progress-value {
    font-size: 18px;
    font-weight: bold;
    color: #00FF88;
    font-family: 'Courier New', monospace;
    text-shadow: 0 0 15px rgba(0, 255, 136, 0.6);
  }
}

.progress-wrapper {
  position: relative;
  margin-bottom: 15px;
}

.progress-bg {
  position: relative;
  height: 20px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 10px;
  border: 1px solid rgba(0, 255, 255, 0.2);
  overflow: hidden;
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, 
      rgba(0, 255, 255, 0.1) 0%, 
      rgba(0, 255, 255, 0.05) 50%, 
      rgba(0, 255, 255, 0.1) 100%
    );
  }
}

.progress-track {
  position: relative;
  height: 100%;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, 
    #00FFFF 0%, 
    #00FF88 50%, 
    #0088FF 100%
  );
  border-radius: 10px;
  position: relative;
  transition: width 0.1s ease-out;
  box-shadow: 
    0 0 20px rgba(0, 255, 255, 0.6),
    inset 0 2px 4px rgba(255, 255, 255, 0.3);
  
  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, 
      rgba(255, 255, 255, 0.4) 0%, 
      transparent 100%
    );
    border-radius: 10px 10px 0 0;
  }
}

.progress-glow {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 4px;
  height: calc(100% + 4px);
  background: linear-gradient(180deg, 
    rgba(0, 255, 255, 0.8) 0%, 
    rgba(0, 255, 136, 0.8) 100%
  );
  border-radius: 2px;
  box-shadow: 0 0 15px rgba(0, 255, 255, 0.8);
  animation: pulse 2s ease-in-out infinite;
}

.progress-particles {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  
  .particle {
    position: absolute;
    width: 2px;
    height: 2px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    animation: float 3s linear infinite;
    
    &:nth-child(1) { left: 10%; animation-delay: 0s; }
    &:nth-child(2) { left: 25%; animation-delay: 0.5s; }
    &:nth-child(3) { left: 40%; animation-delay: 1s; }
    &:nth-child(4) { left: 55%; animation-delay: 1.5s; }
    &:nth-child(5) { left: 70%; animation-delay: 2s; }
    &:nth-child(6) { left: 85%; animation-delay: 2.5s; }
  }
}

.progress-indicators {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  
  .indicator {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 12px;
    background: rgba(0, 255, 255, 0.3);
    border-radius: 1px;
    transition: all 0.3s ease;
    
    &.active {
      background: rgba(0, 255, 255, 0.8);
      box-shadow: 0 0 8px rgba(0, 255, 255, 0.6);
      height: 16px;
    }
  }
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  align-items: center;
  
  .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    
    .stat-label {
      font-size: 12px;
      color: rgba(0, 255, 255, 0.7);
      margin-bottom: 2px;
    }
    
    .stat-value {
      font-size: 14px;
      font-weight: 600;
      font-family: 'Courier New', monospace;
      
      &.status-normal {
        color: #00FF88;
        text-shadow: 0 0 8px rgba(0, 255, 136, 0.5);
      }
      
      &.status-warning {
        color: #FFD700;
        text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
      }
      
      &.status-error {
        color: #FF4444;
        text-shadow: 0 0 8px rgba(255, 68, 68, 0.5);
      }
    }
  }
}

@keyframes scan {
  0% { left: -100%; }
  100% { left: 100%; }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scaleY(1); }
  50% { opacity: 0.7; transform: scaleY(1.1); }
}

@keyframes float {
  0% { 
    transform: translateY(0px) scale(1);
    opacity: 0;
  }
  10% { 
    opacity: 1;
  }
  90% { 
    opacity: 1;
  }
  100% { 
    transform: translateY(-20px) scale(0.5);
    opacity: 0;
  }
}

// 响应式设计
@media (max-width: 768px) {
  .sci-fi-progress-container {
    padding: 15px;
  }
  
  .progress-header {
    .progress-label {
      font-size: 14px;
    }
    
    .progress-value {
      font-size: 16px;
    }
  }
  
  .progress-bg {
    height: 16px;
  }
}
</style>
